<template>
  <el-dialog title="筛选培训计划" width="500" :before-close="handleClose">
    <el-form :model="form" label-width="auto">
      <el-form-item label="培训类型">
        <el-checkbox-group v-model="form.trainingTypes">
          <el-checkbox label="理论学习">理论学习</el-checkbox>
          <el-checkbox label="技能实操">技能实操</el-checkbox>
          <el-checkbox label="考核评估">考核评估</el-checkbox>
          <el-checkbox label="综合培训">综合培训</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="时间范围">
        <el-select
          v-model="form.timeRange"
          placeholder="请选择"
          style="width: 100%; margin-bottom: 10px"
        >
          <el-option label="全部时间" value="全部时间" />
          <el-option label="今天" value="今天" />
          <el-option label="本周" value="本周" />
          <el-option label="本月" value="本月" />
          <el-option label="未来30天" value="未来30天" />
          <el-option label="自定义" value="自定义" />
        </el-select>
        <el-row :gutter="10" v-if="form.timeRange === '自定义'">
          <el-col :span="12">
            <el-date-picker
              v-model="form.customStartDate"
              type="date"
              placeholder="开始日期"
              style="width: 100%"
            />
          </el-col>
          <el-col :span="12">
            <el-date-picker
              v-model="form.customEndDate"
              type="date"
              placeholder="结束日期"
              style="width: 100%"
            />
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="状态">
        <el-checkbox-group v-model="form.statuses">
          <el-checkbox label="计划中">计划中</el-checkbox>
          <el-checkbox label="进行中">进行中</el-checkbox>
          <el-checkbox label="已完成">已完成</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="applyFilter"> 应用筛选</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive } from "vue";
import { ElMessage } from "element-plus";

const dialogVisible = ref(false);
const form = reactive({
  trainingTypes: ["理论学习", "技能实操", "考核评估", "综合培训"],
  timeRange: "全部时间",
  customStartDate: "",
  customEndDate: "",
  statuses: ["计划中", "进行中"],
});

const open = () => {
  dialogVisible.value = true;
};

const handleClose = () => {
  dialogVisible.value = false;
  // Optionally reset form here
  Object.assign(form, {
    trainingTypes: ["理论学习", "技能实操", "考核评估", "综合培训"],
    timeRange: "全部时间",
    customStartDate: "",
    customEndDate: "",
    statuses: ["计划中", "进行中"],
  });
};

const applyFilter = () => {
  // Implement your filter logic here
  console.log("应用的筛选条件:", form);
  ElMessage.success("筛选已应用！");
  handleClose();
};

defineExpose({
  open,
});
</script>

<style scoped>
/* You can add custom styles here if needed */
</style>
